About the Demo
This example shows how to use Eco with ASP.Net. It is
intentionally "simple" in that it concentrates on Eco Aspects only, and
not on general ASP.NET aspects. It also shows a simple example of
implementing a WebService.
Setup Information
No setup should be needed for running this demo under
Cassini.
If you are planning to run this ASP demo under IIS it is
necessary to create a Virtual Directory with IIS. The easiest way of
doing this is as follows:
-
From the Projectmenu, select Options
-
Select to ASP.Net
-
Click on the Server Optionsbutton
- Change the Alias Name (e.g. add a '1' at the end
of the Server Name)
-
hit OKto close the
Server Options dialog, and OKto
close the Project Options dialog. This will force the Project
manager to create a new ASP directory with the new Project Name
In addition you need to change the
BdpConnection1.DatabaseName to an absolute path including the machine
name. Something like "localhost:c:\program
files\Borland\BDS\3.0\Demos\Delphi.Net\ECO\ASP\SimpleWebDemo\Database\SimpleEcoWebDemo.gdb"
Running the Demo
This section should list the steps necessary for the user to get
the demo loading into the IDE and running.
- Press F9 in the IDE
The description of the steps below should giva a good idea
of what to look for in the code, and when using the application.
You can test the webservices in IE by browsning to
OrderServices.ASPX, and observe the effects in another Browser window
by pressing F5.
Steps
This is a list of most of the steps needed for creating the
Demo from scratch.
Setup
- File|NewDelphi for .Net Projects|Eco ASP.Net Web
application
-
Compile, Close and reopen project (This ensures that the PersistenceMapperProvder.EcoSpaceType, PersistenceMapperSharer1.MapperProvider
and rhRoot.EcoSpaceType
will not loose their values).
- Place and connect Persistence components on
EcoPersistenceMapperProvider
-
Set the SyncActive
property on the PersistenceMapper
used to true.
- Draw Model. If using the same model, please
note that since Order is a reserved word in SQL you need to set two
tagged values. Order.Table Name="OrderTable" and
OrderItem.Order.Coumn Name="OrderColumn".
- Create Database
Creating the Main form
-
Place a button Create Test
Data, and add Code to Create Test Data.
Note that all events that change things will normally end with
UpdateDataBase(); DataBind().
-
Place and ExpressionHandle, and set RootHandle=rhroot, Expression="Order.allInstaces", AddExternalId=true.
-
Place a Datagrid on the form, and set its DataSource
to the Expression handle created in step 8, and the DataKeyField="ExternalId";
-
Open the Editor for the Columns
property. Uncheck "Create columns...", and select all
columns except ExternalId.
You can now test run the application.
Making the grid Editable
There is some code in the template that can be used for
making the grid editable. It can also be mined for "how to do things in
code".
- Connect the events CancelCommand, DeleteCommand,
EditCommand and UpdateCommand to the method with the corresponding
name.
- Open the Columns editor again from the Button
commands select first "Edit, Update, Cancel" and then Delete.
Run the application again, and try out the options.
Creating and using the detail form
There is some code in the template that can be used for
making the grid editable. It can also be mined for "how to do things in
code".
- Add a new Eco webform
- Set rhRoot.EcoSpacetype, and Set
RhRoot.StaticValueType to "Order". This indactes that th
referenceHandle will always point to an Order, and is needed to
enable designtime OCL support. Note that the code in Page_Load will
setup rhRoot if the URL contains an external ID.
- Add three textboxes for the three attributes of
Order, adn connecdt them to rhRoot[0].Customer etc using the editor
on the Data
-
Add an expressionhandle, RootHandle=rhroot, Expression="self.OrderItem", AddExternalId=true.
- Add a grid, and connect it up the same way as
before.
- Add a button with code for updating changes to the
attributes. The example contains three ways of doing this, with
comments.
- If you want to show off, add an ExpressionHandle
for the OrderTotal, and Connect a Label to it.
- Now go back to the main from, and add a button for
creating a new Order and showing it the the deatil form. Look at the
code in the Example.
Editing in the detail form
Finally add code in the main form to open the details form
for a given row in the grid:
- Open the Colums editor on the grid on the main
form
- Add a Hyperrlink Column
-
Set Text=Detail, URL
Field=ExternalId, URL
Format String= OrderForm.aspx?RootId={0}
Enjoy!
Troubleshooting
The file web.config contains lines of the form:
<add assembly="Borland.Eco.Handles, Version=x.x.x.x, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b"/>
If you get an error message at runtime indicating that the
compiler can't find one of these assemblies, you may need to update the
version number. The correct version number can be found by double
clicking on the DLL in the project manager.
These lines are only needed if the assemblies are to be
found in the GAC. If the assembiles are deployed with the application,
there lines can be removed from Web.config.